package net.edu_soft.ec.asset.controller;


import net.edu_soft.ec.asset.pojo.ProductType;
import net.edu_soft.ec.asset.service.ProductTypeService;
import net.edu_soft.ec.common.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  @author: PUING
 *  @Date: 2020/4/17 10:10
 *  @Description: 产品分类控制器
 */
@RestController
@RequestMapping(value = "/proType")
public class ProductTypeController {

    @Autowired
    private ProductTypeService typeService;

    /***
     * 查询单个产品分类
     * @param id 产品分类id
     * @return
     */
    @RequestMapping(value = "/find")
    public ResultVo find(Integer id){
        return ResultVo.succeed("查询单个产品分类",typeService.find(id));
    }

    /***
     * 分页查询产品分类列表信息
     * @param name 分类名
     * @param parentId 上一级
     * @param rank 分类等级
     * @param pageNum 当前页
     * @param pageSize 每页数
     * @return 产品分类信息
     */
    @RequestMapping(value = "/findList")
    public ResultVo findList(String name, Integer parentId, Integer rank, Integer pageNum, Integer pageSize){

        return ResultVo.succeed("查询产品分类列表",typeService.findList(name,parentId,rank,pageNum,pageSize));
    }

    /***
     * 添加产品分类
     * @param productType 产品分类
     * @return
     */
    @RequestMapping(value = "/save")
    public ResultVo save(ProductType productType){
        if(typeService.save(productType)==1){
            return ResultVo.succeed("添加成功",null);
        }else {
            return ResultVo.succeed("添加失败",null);
        }
    }

    /***
     * 修改产品分类
     * @param productType 产品分类
     * @return
     */
    @RequestMapping(value = "/update")
    public ResultVo update(ProductType productType){
        if(typeService.update(productType)==1){
            return ResultVo.succeed("修改成功",null);
        }else {
            return ResultVo.succeed("修改失败",null);
        }
    }

    /***
     * 删除产品分类
     * @param typeIds 产品分类串
     * @param isDel 是否删除 0否 1删除
     * @return
     */
    @RequestMapping(value = "/del")
    public ResultVo del(String typeIds,Integer isDel){
        if(typeService.del(typeIds,isDel)==1){
            return ResultVo.succeed("删除成功",null);
        }else {
            return ResultVo.succeed("删除失败",null);
        }
    }

}
